const _function = require("../../utils/functionData.js")
Page({
  data: {
    chatList: [
      // {
      //   id: 1,
      //   avatar: 'https://img.yzcdn.cn/vant/cat.jpeg',
      //   username: '好友1',
      //   lastMessage: '你好！',
      //   time: '10:00'
      // },
      // {
      //   id: 2,
      //   avatar: 'https://img.yzcdn.cn/vant/cat.jpeg',
      //   username: '好友2',
      //   lastMessage: '在吗？',
      //   time: '09:30'
      // },


      // 更多聊天项...
    ],
    role: 0,
    _UrlGet_: wx.getStorageSync('img_url')
  },

  navigateToChat: function (event) {
    const item = event.currentTarget.dataset.item;
    // wx.navigateTo({
    //   url: `/pages/chat/chat?id=${chatId}`
    // });
    wx.navigateTo({
      url: `/pages/chat/chat?data=${encodeURIComponent(JSON.stringify(item))}`
    });
  },
  // onLoad() {
  //   this.getHotJob()
  //   this.getHotTeacher()
  // },

  onShow() {
    this.setData({
      role: getApp().globalData.userInfo.role
    })
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1 //这个数字是当前页面在tabBar中list数组的索引
      })
    }
    this.getMessageList()
  },
  getMessageList() {
    console.log('获取聊天列表');
    _function.getMessageList(this.data.param, this.getMessageListBack, this)
  },
  getMessageListBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      this.setData({
        chatList: dataAll.rows
      })
    }
  }
});